﻿Imports DTO
Imports BUS
Public Class frmCHITIETPHIEUXUAT

    Private Sub frmPHIEUXUATKHO_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DBNGKDataSet9.KHO' table. You can move, or remove it, as needed.

        loadSP()
        loadCBbSP()
        loadKho()
    End Sub
    Private Sub loadCBbSP()
        cbo_tenSP.DataSource = MatHangBUS.LayTatCaTT()
        cbo_tenSP.DisplayMember = "TenSP"
        cbo_tenSP.ValueMember = "MaSP"
    End Sub

    Private Sub loadKho()
        cbb_tenkho.DataSource = KhoBUS.LAYTATCA()
        cbb_tenkho.DisplayMember = "TenKho"
        cbb_tenkho.ValueMember = "MaKho"
    End Sub
    Private Sub loadSP()
        dgv_chitiet.DataSource = PhieuGiaoBUS.LAYTATCATT()

    End Sub
    Private Sub btn_thoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub


    Private Sub btn_them_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_them.Click
        If txt_SoLuong.Text <> "" And dtp_ngayxuat.Text <> "" And cbb_tenkho.Text <> "" And cbo_tenSP.Text <> "" Then
            Dim pxdto As New PhieuGiaoDTO()
            pxdto.NgayGiao = dtp_ngayxuat.Value
            pxdto.MaHang = cbo_tenSP.SelectedValue
            pxdto.MaKho = cbb_tenkho.SelectedValue
            pxdto.SoLuong = txt_SoLuong.Text
            PhieuGiaoBUS.THEM(pxdto)
            loadSP()
            MessageBox.Show("Da Them Thanh Cong!", "Thong Bao")
        End If
    End Sub

    Private Sub btn_thoat_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_thoat.Click
        Me.Close()
    End Sub

    Private Sub btn_xoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_xoa.Click
        Dim nv As New PhieuGiaoDTO()
        nv.MaPG = dgv_chitiet.Rows(index).Cells(0).Value
        PhieuGiaoBUS.XOA(nv.MaPG)
        loadSP()
        MessageBox.Show("Da Xoa Thanh Cong!")
    End Sub
    Dim index As Integer
    Private Sub dgv_chitiet_RowEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv_chitiet.RowEnter
        index = e.RowIndex
    End Sub
End Class